package com.wypiwyl.footastic;

public enum Direction {
    NONE(0, 0),
    NORTH(1, 270),
    NORTH_EAST(2, 315),
    EAST(3, 0),
    SOUTH_EAST(4, 45),
    SOUTH(5, 90),
    SOUTH_WEST(6, 135),
    WEST(7, 180),
    NORTH_WEST(8, 225);
    
    private int value;
    private int angle;
    
    private Direction(int _value, int _angle) {
        this.value = _value;
        this.angle = _angle;
    }

    public int getValue() {
        return value;
    }
    
    public int getAngle() {
        return angle;
    }

    public static Direction getDirection(int value) {
        for (Direction direction : values()) {
            if (direction.getValue() == value) {
                return direction;
            }
        }
        return null;
    }
    
    public static Direction rotateH(Direction direction) {
        
        int valueRotated;
        
        if (direction.getValue() == 8) {
            valueRotated = 1;
        } else {
            valueRotated = direction.getValue() + 1;
        }
        
        return getDirection(valueRotated);
    }
    
    public static Direction rotateAH(Direction direction) {
        
        int valueRotated;
        
        if (direction.getValue() == 1) {
            valueRotated = 8;
        } else {
            valueRotated = direction.getValue() - 1;
        }
        
        return getDirection(valueRotated);
    }
}
